package com.pd.backend.service.impl;

import com.pd.backend.entity.PdCacheLineDetail;
import com.pd.backend.dao.PdCacheLineDetailDao;
import com.pd.backend.service.PdCacheLineDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 缓冲路线子表(PdCacheLineDetail)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:32
 */
@Service("pdCacheLineDetailService")
public class PdCacheLineDetailServiceImpl implements PdCacheLineDetailService {
    @Resource
    private PdCacheLineDetailDao pdCacheLineDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdCacheLineDetail queryById(String id) {
        return this.pdCacheLineDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdCacheLineDetail 筛选条件
     * @param pageRequest       分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdCacheLineDetail> queryByPage(PdCacheLineDetail pdCacheLineDetail, PageRequest pageRequest) {
        long total = this.pdCacheLineDetailDao.count(pdCacheLineDetail);
        return new PageImpl<>(this.pdCacheLineDetailDao.queryAllByLimit(pdCacheLineDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdCacheLineDetail 实例对象
     * @return 实例对象
     */
    @Override
    public PdCacheLineDetail insert(PdCacheLineDetail pdCacheLineDetail) {
        this.pdCacheLineDetailDao.insert(pdCacheLineDetail);
        return pdCacheLineDetail;
    }

    /**
     * 修改数据
     *
     * @param pdCacheLineDetail 实例对象
     * @return 实例对象
     */
    @Override
    public PdCacheLineDetail update(PdCacheLineDetail pdCacheLineDetail) {
        this.pdCacheLineDetailDao.update(pdCacheLineDetail);
        return this.queryById(pdCacheLineDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdCacheLineDetailDao.deleteById(id) > 0;
    }
}
